package com.novice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.novice.domain.entity.Order;
import com.novice.domain.pojo.User;
import com.novice.mapper.OrderMapper;
import com.novice.service.IOrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;


@Service
@Transactional(rollbackFor = Exception.class)
public class IOrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
    @Resource
    private RestTemplate restTemplate;

    @Override
    public Order getOrderById(Long orderId) {
        Order order = baseMapper.selectById(orderId);
        String url = "http://userservice/user/" + order.getUserId();
        // 利用restTemplate 发起远程调用，获取用户信息
        User forObject = restTemplate.getForObject(url, User.class);
        order.setUser(forObject);
        return order;
    }
}
